package com.keeping.aiimagery.service.impl;

import com.keeping.aiimagery.entity.LoginDto;
import com.keeping.aiimagery.entity.UpdataVo;
import com.keeping.aiimagery.entity.User;
import com.keeping.aiimagery.mapper.UserMapper;
import com.keeping.aiimagery.resouce.TokenUtil;
import com.keeping.aiimagery.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;


/**
 * <p>
 * 用户 服务实现类
 * </p>
 *
 * @author keeping
 * @since 2023-04-05
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Resource
    UserMapper userMapper;

    public void updataById(UpdataVo updataVo){
         userMapper.updataById(updataVo);
    }
    public Integer getIntegralById(String userAccount){
        return userMapper.getIntegralById(userAccount);
    }
    public Integer findByAccount(String userAccount){
        return userMapper.findIdByAccount(userAccount);
    }
    public HashMap<String, String> userLogin(String userAccount, String password) {
        HashMap<String, String> map = new HashMap<>();
        System.out.println(userMapper);
        User user = userMapper.login(userAccount);
        if(user==null){
            map.put("judge","1");
        }
        if ( user.getUserPassword().equals(password)) {
            map.put("judge","0");
            map.put("userId",user.getId().toString());
            map.put("roleId",user.getRoleId().toString());
        }else {
            map.put("judge","2");
        }
        return map;
    }
    @Override
    public void insert(String username, String password, String phone,String invitationCode){
        userMapper.insert(username,password,phone,invitationCode);
    }
    public User findUser(String userAccount){
        return userMapper.login(userAccount);
    }
    public Integer findByYaoqingma(String invitationCode){
        return userMapper.findByYaoqingma(invitationCode);
    }
    public void updataByInvite(UpdataVo updataVo){
        userMapper.updataByInvite(updataVo);
    }
    public boolean findphone(String phone){
        String p=userMapper.findphone(phone);
        if(p!=null) return true;
        return false;
    }

    public User getmsg(String phone){
        return userMapper.getmsg(phone);
    }

    public void updateconsume(Integer integral,Integer remain, String userId)
    {
        userMapper.updateconsume(integral,remain,userId);
    }

    public void updateconsumecount(Integer integral,Integer remaincount, String userId)
    {
        userMapper.updateconsumecount(integral,remaincount,userId);
    }

    public void updateconsumestorage(Integer integral,Integer remainstorage, String userId)
    {
        userMapper.updateconsumestorage(integral,remainstorage,userId);
    }
}
